import config from '../../../build/config';
export const headImg = {
  computed: {
    headImgPath () {
      return sessionStorage.headImg ? config.imgUrl + sessionStorage.headImg : require('@/images/defaultImg.jpg');
    }
  }
};

export const indexPage = {
  data () {
    return {
      tableLoading: false,
      apiFn: {},
      tableData: [],
      tableShow: {
        currentPage: 1,
        pageSize: 10,
        listCount: 0
      },
      searchConf: {
        type: '',
        keywords: '',
        status: ''
      },
      modalSetting: {
        show: false,
        loading: false,
        index: 0
      },
    }
  },
  created () {
    this.init();
    this.getList();
  },
  methods: {
    async getList () {
      let vm = this;
      this.tableLoading = true;
      let args = {
        page: vm.tableShow.currentPage,
        size: vm.tableShow.pageSize,
        status: vm.searchConf.status,
        type: vm.searchConf.type,
        keywords: vm.searchConf.keywords
      };
      let data = await vm.apiFn.call(vm,args)

      vm.tableData = data.list;
      vm.tableShow.listCount = data.count;
      this.tableLoading = false;
    },
    cancel () {
      this.modalSetting.show = false;
    },
    changePage (page) {
      this.tableShow.currentPage = page;
      this.getList();
    },
    changeSize (size) {
      this.tableShow.pageSize = size;
      this.getList();
    },
    search () {
      this.tableShow.currentPage = 1;
      this.getList();
    },
    doCancel (data) {
      if (!data) {
        this.formItem.id = 0;
        this.$refs['myForm'].resetFields();
        this.modalSetting.loading = false;
        this.modalSetting.index = 0;
      }
    }
  }
}


// 以下是测试用的

export const getList = {
  data () {
    return {
      tableLoading: false
    }
  },
  methods: {
    async getList (api) {
      let vm = this;
      this.tableLoading = true;
      let data = await api.call({
        page: vm.tableShow.currentPage,
        size: vm.tableShow.pageSize,
        type: vm.searchConf.type,
        keywords: vm.searchConf.keywords
      })

      // test.log();
      vm.tableData = data.list;
      vm.tableShow.listCount = data.count;
      this.tableLoading = false;
    }
  }
};

export const test = {
  log () {
    console.log('dddddd')
  }
}